﻿using System.IO;
using System.Net;

namespace CkSoftware.GroupMe.Sdk.Core
{
	/// <summary>
	/// CommandParameter for a FileUpload based WebApi command. Used currently for image-upload to the imaging service.
	/// </summary>
	public class FileUploadWebApiCommandParameter : IWebApiCommandParameters
	{
		/// <summary>
		/// Instantiate a new <see cref="FileUploadWebApiCommandParameter" /> using the given web-url, name and filename.
		/// </summary>
		/// <param name="webUrlToFile">
		/// The url to a web-location which will be downloaded immediately and stored in the FileData
		/// property.
		/// </param>
		/// <param name="name">The name of the upload. This will be used by the content-processing for naming a given HTTP content.</param>
		/// <param name="fileName">The file-name of the given file.</param>
		public FileUploadWebApiCommandParameter(string webUrlToFile, string name, string fileName)
		{
			Name = name;
			FileName = fileName;
			WebRequest request = WebRequest.Create(webUrlToFile);
			WebResponse response = request.GetResponse();
			FileData = response.GetResponseStream();
		}

		/// <summary>
		/// Instantiate a new <see cref="FileUploadWebApiCommandParameter" /> using the given fileData stream, name and filename.
		/// </summary>
		/// <param name="fileData">The stream which should be used as file-upload.</param>
		/// <param name="name">The name of the upload. This will be used by the content-processing for naming a given HTTP content.</param>
		/// <param name="fileName">The file-name of the given file.</param>
		public FileUploadWebApiCommandParameter(Stream fileData, string name, string fileName)
		{
			Name = name;
			FileName = fileName;
			FileData = fileData;
		}

		/// <summary>
		/// The stream of the file data to upload.
		/// </summary>
		public Stream FileData { get; private set; }

		/// <summary>
		/// The file-name of the given file.
		/// </summary>
		public string FileName { get; set; }

		/// <summary>
		/// The name of the upload. This will be used by the content-processing for naming a given HTTP content.
		/// </summary>
		public string Name { get; set; }
	}
}